package com.quanshu.exchange.ui.gui.message.chat.row.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyphenate.chat.EMMessage;
import com.hyphenate.exceptions.HyphenateException;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.chat.ChatConstant;
import com.quanshu.exchange.ui.gui.message.chat.row.BaseChatRowViewHolder;

// 接收红包消息ViewHolder
public class RedPackageReceiveViewHolder extends BaseChatRowViewHolder {
    TextView redPackageName;
    ImageView redPackageBg;

    public RedPackageReceiveViewHolder(Context context, View view) {
        super(context, view);
        redPackageName = view.findViewById(R.id.chat_red_package_name);
        redPackageBg = view.findViewById(R.id.chat_red_package_bg);
    }

    @Override
    public void setViewInfo(EMMessage chatMessage, EMMessage preMessage, String groupOwner) {
        super.setViewInfo(chatMessage, preMessage, groupOwner);
        // 设置
        try {
            String name = chatMessage.getStringAttribute(ChatConstant.Chat_ext_attr_red_package_name);
            if (name != null) {
                redPackageName.setText(name);
            } else {
                redPackageName.setText("");
            }
        } catch (HyphenateException e) {
            e.printStackTrace();
            redPackageName.setText("");
        }

        boolean isRobed = chatMessage.getBooleanAttribute(ChatConstant.Chat_ext_attr_red_package_is_robed, false);
        if (isRobed) {
            redPackageBg.setBackgroundResource(R.drawable.bg_chat_row_red_package_isrobed);
        } else {
            redPackageBg.setBackgroundResource(R.drawable.bg_chat_row_red_package);
        }
    }
}